package drinkkiosk.buttons;

import drinkkiosk.CardPanel;
import drinkkiosk.cards.SpecialsCard;
import java.awt.CardLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;

/**NavigationButton is the parent class of all buttons that change
 * the currently displayed view to another view e.g. from Custom Drink
 * to the Welcome Screen.
 * @author Charles Ritchea
 */
public class NavigationButton extends JButton implements ActionListener{
	/**cardName is the String CardLayout associates with
	 * a particular JPanel
	 * @see CardLayout
	 * @see JPanel
	 */
	private String cardName;
	/**NavigationButtion(String cardName) is used by child classes
	 * to customize their target card.
	 * @param cardName String used to show a JPanel
	 * @see JPanel
	 */
	public NavigationButton(String cardName){
		this.cardName = cardName;
		setFont(new java.awt.Font("Arial", 0, 36));
		addActionListener(this);
	}
	/**actionPerformed tells the CardLayout to show a particular
	 * JPanel based on cardName.
	 * @param evt the ActionEvent for when the button is clicked. 
	 * @see ActionEvent
	 */
	@Override
	public void actionPerformed(ActionEvent evt) {
		NavigationButton button = (NavigationButton)evt.getSource();
		JLayeredPane layer = (JLayeredPane)button.getParent();
		JPanel card = (JPanel)layer.getParent();
		CardPanel cardPanel = (CardPanel)card.getParent();
		CardLayout cardLayout = (CardLayout)cardPanel.getLayout();
		cardLayout.show(cardPanel, cardName.toLowerCase());
		if("specials".equals(cardName)){
			SpecialsCard specialsCard = (SpecialsCard) cardPanel.getSpecialsCard();
			specialsCard.setSpecial(specialsCard.getSpecialsList().getFirst());
			specialsCard.getDisplaySpecialPanel1().setComponents(specialsCard.getSpecial());
		}
	}
}